package cn.com.thingo.hyintelligent.model.prefs;

import android.content.Context;
import android.content.SharedPreferences;


import javax.inject.Inject;

import cn.com.thingo.hyintelligent.app.App;
import cn.com.thingo.hyintelligent.app.Constants;

/**
 * Created by Administrator on 2017/10/9.
 */

public class ImplPreferencesHelper implements PreferencesHelper {

    private static final String DEFAULT_LOGIN_USERNAME = "";
    private static final String DEFAULT_LOGIN_PWD = "";
    private static final boolean DEFAULT_LOGIN_STATE = false;


    private static final boolean DEFAULT_NIGHT_MODE = false;
    private static final boolean DEFAULT_NO_IMAGE = false;
    private static final boolean DEFAULT_AUTO_SAVE = true;

    private static final boolean DEFAULT_LIKE_POINT = false;
    private static final boolean DEFAULT_VERSION_POINT = false;
    private static final boolean DEFAULT_MANAGER_POINT = false;

    private static final int DEFAULT_CURRENT_ITEM = Constants.TYPE_ZHIHU;

    private static final String SHAREDPREFERENCES_NAME = "my_sp";

    private final SharedPreferences mSPrefs;

    @Inject
    public ImplPreferencesHelper() {
        mSPrefs = App.getInstance().getSharedPreferences(SHAREDPREFERENCES_NAME, Context.MODE_PRIVATE);
    }


    @Override
    public String getUserName() {
        return mSPrefs.getString(Constants.SP_LOGIN_USERNAME, DEFAULT_LOGIN_USERNAME);
    }

    @Override
    public void setUserNameAndPwd(String userName , String pwd) {
        mSPrefs.edit().putString(Constants.SP_LOGIN_USERNAME, userName).apply();
        mSPrefs.edit().putString(Constants.SP_LOGIN_PWD,pwd).apply();
    }

    @Override
    public String getPwd() {
        return mSPrefs.getString(Constants.SP_LOGIN_PWD, DEFAULT_LOGIN_PWD);
    }


    @Override
    public SharedPreferences getSPrefs() {
        return mSPrefs;
    }

    @Override
    public boolean getLoginState() {
        return mSPrefs.getBoolean(Constants.SP_LOGIN_STATE, DEFAULT_LOGIN_STATE);
    }

    @Override
    public void setLoginState(boolean state) {
        mSPrefs.edit().putBoolean(Constants.SP_LOGIN_STATE, state).apply();
    }

    @Override
    public boolean getRememberPW() {
        return mSPrefs.getBoolean(Constants.SP_REMENBER_PW, DEFAULT_LOGIN_STATE);
    }

    @Override
    public void setRememberPW(boolean state) {
        mSPrefs.edit().putBoolean(Constants.SP_REMENBER_PW, state).apply();
    }

    @Override
    public boolean getNightModeState() {
        return mSPrefs.getBoolean(Constants.SP_NIGHT_MODE, DEFAULT_NIGHT_MODE);
    }

    @Override
    public void setNightModeState(boolean state) {
        mSPrefs.edit().putBoolean(Constants.SP_NIGHT_MODE, state).apply();
    }

    @Override
    public boolean getNoImageState() {
        return mSPrefs.getBoolean(Constants.SP_NO_IMAGE, DEFAULT_NO_IMAGE);
    }

    @Override
    public void setNoImageState(boolean state) {
        mSPrefs.edit().putBoolean(Constants.SP_NO_IMAGE, state).apply();
    }

    @Override
    public boolean getAutoCacheState() {
        return mSPrefs.getBoolean(Constants.SP_AUTO_CACHE, DEFAULT_AUTO_SAVE);
    }

    @Override
    public void setAutoCacheState(boolean state) {
        mSPrefs.edit().putBoolean(Constants.SP_AUTO_CACHE, state).apply();
    }

    @Override
    public int getCurrentItem() {
        return mSPrefs.getInt(Constants.SP_CURRENT_ITEM, DEFAULT_CURRENT_ITEM);
    }

    @Override
    public void setCurrentItem(int item) {
        mSPrefs.edit().putInt(Constants.SP_CURRENT_ITEM, item).apply();
    }

    @Override
    public boolean getLikePoint() {
        return mSPrefs.getBoolean(Constants.SP_LIKE_POINT, DEFAULT_LIKE_POINT);
    }

    @Override
    public void setLikePoint(boolean isFirst) {
        mSPrefs.edit().putBoolean(Constants.SP_LIKE_POINT, isFirst).apply();
    }

    @Override
    public boolean getVersionPoint() {
        return mSPrefs.getBoolean(Constants.SP_VERSION_POINT, DEFAULT_VERSION_POINT);
    }

    @Override
    public void setVersionPoint(boolean isFirst) {
        mSPrefs.edit().putBoolean(Constants.SP_VERSION_POINT, isFirst).apply();
    }

    @Override
    public boolean getManagerPoint() {
        return mSPrefs.getBoolean(Constants.SP_MANAGER_POINT, DEFAULT_MANAGER_POINT);
    }

    @Override
    public void setManagerPoint(boolean isFirst) {
        mSPrefs.edit().putBoolean(Constants.SP_MANAGER_POINT, isFirst).apply();
    }
}
